package com.ultimatepolish.scorebookdb;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;

import android.content.Context;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable
public class Session {
	@DatabaseField(generatedId=true)
	private long id;
	
	@DatabaseField(canBeNull=false)
	private String sessionName;
	
	@DatabaseField(canBeNull=false)
	private Date startDate;
	
	@DatabaseField(canBeNull=true)
	private Date endDate;
	
	@DatabaseField(canBeNull=false)
	public boolean isLeague = false;
	
	public Session(){}

	public Session(String sessionName, Date startDate) {
		super();
		this.sessionName = sessionName;
		this.startDate = startDate;
		
	}
	
	public static Dao<Session, Long> getDao(Context context) throws SQLException{
		DatabaseHelper helper = new DatabaseHelper(context);
		Dao<Session, Long> d = helper.getSessionDao();
		return d;
	}
	public static ArrayList<Session> getAll(Context context) throws SQLException{
		Dao<Session, Long> d = Session.getDao(context);
		ArrayList<Session> sessions = new ArrayList<Session>();
		for(Session s:d){
			sessions.add(s);
		}
		return sessions;
	}
	

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getSessionName() {
		return sessionName;
	}

	public void setSessionName(String sessionName) {
		this.sessionName = sessionName;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	
	
	
	
}
